package ar.edu.unq.mongodbexample.tests.persitence;

import java.util.ArrayList; 
import java.util.List;

import junit.framework.TestCase;
import ar.edu.unq.mongodbexample.homes.StudentHome;
import ar.edu.unq.mongodbexample.model.Student;
import ar.edu.unq.mongodbexample.persistence.MongoDBManager;

/**
 * TODO: description
 */
public class StudentHomeTestCase extends TestCase {

	StudentHome home;
	List<Student> students;
	public void setUp(){
		home=new StudentHome();
		students=createStudents();
	}
	public void tearDown(){
		MongoDBManager.getInstance().getDataStore().getCollection(Student.class).drop();
	}
    public void testSaveAndGetStudentByDni() {
    	Student student = new Student(31702882,19523,"UnApellido","UnNombre","unemailmorphia@mail.com");
        home.save(student);
        Student studentFound= home.findById(31702882);
        assertEquals(studentFound.getDni(), 31702882);
    }
    
    public void testSaveAllAndGetAllStudents() {
    	home.saveAll(students);
    	List<Student> studentsList= home.getAll();
        assertEquals(studentsList.size(), 4);
    }

    private List<Student> createStudents() {
    	List<Student> studentsList=new ArrayList<Student>();
        studentsList.add(new Student(00000001,19523,"UnApellido1","UnNombre1","unemailmorphia1@mail.com"));
        studentsList.add(new Student(00000002,19524,"UnApellido2","UnNombre2","unemailmorphia2@mail.com"));
        studentsList.add(new Student(00000003,19525,"UnApellido3","UnNombre3","unemailmorphia3@mail.com"));
        studentsList.add(new Student(00000004,19526,"UnApellido4","UnNombre4","unemailmorphia4@mail.com"));
        return studentsList;
    }
}
